<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拖拽（移动端）</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            position: fixed;
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>
<script>
    let box = document.querySelector('.box');
    function move(a, x, y) {
        if (a) {
            document.ontouchmove = (e) => {
                box.style['left'] = e.touches[0].pageX - x + 'px';
                box.style['top'] = e.touches[0].pageY - y + 'px';
            }
        } else {
            document.ontouchmove = null;
        }
    }
    box.addEventListener('touchstart', function (e) {
        // 触摸开始时接触点的坐标
        let downX = e.touches[0].clientX - box.offsetLeft;
        let downY = e.touches[0].clientY - box.offsetTop;
        move(true, downX, downY);
    });
    box.addEventListener('touchend', function () {
        move(false);
    });
</script>

</html>